home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / option.exe / TEST.CPP < prev    next >
C/C++ Source or Header  |  1992-10-25  |  2KB  |  98 lines

  1. #define Uses_TApplication
  2. #define Uses_THeapApp
  3. #define Uses_TMenuBar
  4. #define Uses_TSubMenu
  5. #define Uses_TMenuItem
  6. #define Uses_TEvent
  7. #define Uses_TKeys
  8. #define Uses_TDialog
  9. #define Uses_TCollection
  10. #define Uses_TOption
  11. #define Uses_TInputLine
  12. #define Uses_TLabel
  13. #define Uses_TDeskTop
  14. #include <tv.h>
  15. #include "TOption.h"
  16. #include "THeapApp.h"
  17.  
  18. const cmTest = 100;
  19.  
  20.  
  21. class TMyApp : public THeapApp
  22.     {
  23.     public:
  24.  
  25.         TMyApp();
  26.  
  27.         static TMenuBar *initMenuBar( TRect r );
  28.  
  29.         virtual void handleEvent( TEvent& event );
  30.     };
  31.  
  32. class TStrCollection : public TCollection
  33.     {
  34.     public:
  35.  
  36.         TStrCollection( ccIndex aLimit, ccIndex aDelta ) :
  37.             TCollection(aLimit, aDelta)    {}
  38.  
  39.         virtual void *readItem( ipstream& )
  40.             {    return this;    }
  41.         virtual void writeItem( void *, opstream& )
  42.             {}
  43.     };
  44.  
  45. TMyApp::TMyApp() :
  46.     TProgInit( &TMyApp::initStatusLine,
  47.                &TMyApp::initMenuBar,
  48.                &TMyApp::initDeskTop
  49.              )
  50.     {
  51.     }
  52.  
  53. TMenuBar *TMyApp::initMenuBar( TRect r )
  54.     {
  55.     r.b.y = r.a.y+1;
  56.     return new TMenuBar( r,
  57.         *new TSubMenu( "~T~est", 0 )+
  58.             *new TMenuItem( "~D~ialog with TOption", cmTest, kbNoKey )+
  59.             *new TMenuItem( "E~x~it", cmQuit, kbAltX, hcNoContext, "Alt-X" )
  60.         );
  61.     }
  62.  
  63. void TMyApp::handleEvent( TEvent& event )
  64.     {
  65.     TApplication::handleEvent( event );
  66.     if( event.what == evCommand && event.message.command == cmTest )
  67.         {
  68.         TDialog *pd = new TDialog( TRect(0,0,50,11), "Test Dialog" );
  69.         if( validView(pd) != 0 )
  70.             {
  71.             TInputLine *pl = new TInputLine( TRect(17,3,44,4), 25 );
  72.             pd->insert( pl );
  73.             pd->insert( new TLabel(TRect(3,3,17,4), "How are you?", pl) );
  74.             TStrCollection *pc = new TStrCollection( 5, 0 );
  75.             pc->insert( newStr( "Great!" ) );
  76.             pc->insert( newStr("Pretty good") );
  77.             pc->insert( newStr("So so") );
  78.             pc->insert( newStr("I've had better days") );
  79.             pc->insert( newStr("Rotten") );
  80.             pd->insert( new TOption(TRect(44,3,47,4), pl, pc) );
  81.             pd->options |= ofCentered;
  82.             deskTop->execView( pd );
  83.             destroy(pd);
  84.             destroy(pc);
  85.             }
  86.         clearEvent(event);
  87.         }
  88.     }
  89.  
  90. int main()
  91.     {
  92.     TMyApp app;
  93.  
  94.     app.run();
  95.     app.shutDown();
  96.     return 0;
  97.     }
  98.